/* 
 * File:   uartStrings.h
 * Author: stevem
 *
 * Created on 8 October 2010, 7:06 AM
 */

#ifndef _UARTSTRINGS_H
#define	_UARTSTRINGS_H

void sh2str(char data, char output[]) {
    output[0] = data / 100;
    data = data - output[0]*100; //Store 100s
    output[1] = data / 10; //Store 10s
    output[2] = data - output[1]*10; //Store 1s
    output[2] += 0x30;
    output[1] += 0x30;
    output[0] += 0x30;
}

void uint2str(unsigned int data, char output[]) {
    output[0] = data / 10000;
    data -= output[0]*10000;
    output[1] = data / 1000;
    data -= output[1]*1000;
    output[2] = data / 100;
    data -= output[2]*100;
    output[3] = data / 10;
    output[4] = data - output[3]*10;
    output[0] += 0x30;
    output[1] += 0x30;
    output[2] += 0x30;
    output[3] += 0x30;
    output[4] += 0x30;
}

inline void newline(void) {
    usb_serial_putchar_nowait('\n'); //Newline CR ASCII Code
    //TODO may also need LF Code
}

inline void space(void) {
    usb_serial_putchar_nowait(32); //Space ASCII Code
    //TODO may also need LF Code
}

void printShort(char data) {
    char str[3];
    sh2str(data, str);
    usb_serial_write(str, 3);
}

void printUint(unsigned int data) {
    char str[5];
    uint2str(data, str);
    usb_serial_write(str, 5);
}

#endif	/* _UARTSTRINGS_H */

